home comics writing pictures archive about

PhpHelper.cpp

Language: C++
Last Modified: 2022-08-18 12:03:01 AM UTC
File Size: 1110 bytes
http://www.penguinstew.ca/example/CodeFormater/PhpHelper.cpp
#include "PhpHelper.h"
#include <string>
#include <sstream>
#include <vector>
std::string PhpHelper::htmlspecialchars(std::string input)
{
std::stringstream stream;
for (unsigned int i = 0; i < input.length(); i++)
{
char c = input.at(i);
switch (c)
{
case '&':
stream << "&amp;";
break;
case '"': stream << "&quot;";
break;
case '<': stream << "&lt;";
break;
case '>': stream << "&gt;";
break;
default:
stream << c;
break;
}
}
return stream.str();
}
std::vector<std::string> PhpHelper::explode(std::string delimiter, std::string str)
{
std::vector<std::string> array;
std::string item;
int delLength = delimiter.length();
unsigned int itemStart = 0;
for (unsigned int i = 0; i < str.length(); i++)
{
if (str.compare(i, delLength, delimiter) == 0)
{
item = str.substr(itemStart, i - itemStart);
array.push_back(item);
i += (delLength - 1);
itemStart = i + 1;
}
}
if (itemStart < str.length())
{
item = str.substr(itemStart);
array.push_back(item);
}
return array;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60